
const baseURL = 'http://localhost:7777/api'



export const request = (options =>{
	
	return new Promise((resolve,reject)=>{
		uni.request({
			url:baseURL+options.url,
			method:options.method || 'GET',
			header:{token:uni.getStorageSync('token')!=null? uni.getStorageSync('token'):' '},
			data:options.data || {},
			success:(res)=>{
				const data = res.data
				if(res.statusCode>=200&&res.statusCode<300){
					resolve(res.data)
				}
				else if(res.statusCode==401){
					uni.navigateTo({
						url:'/pages/login/login'
					})
					uni.showToast({
						icon:'none',
						title:data.msg || "请登录",
					})
					reject(res)
				}else{
					uni.showToast({
						icon:'none',
						title:data.msg || "服务异常",
					})
					reject(res)
				}
				
			},
			fail(err){
				uni.showToast({
					icon:'none',
					title: '网络错误',
				})
				reject(err)
				
			}
		})
	})
})